<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
*/

/**
 * Description of MultiFile
 *
 * @author chaporgin_a
 */
class VA_Form_ViewHelper_XHTML_MultiFile extends VA_Form_ViewHelper_XHTML_File {
    public function wrap() {
        $return = '';
        $this->getElement()->setHTMLTagAttribute('type', 'file', TRUE);
        $values = array(null);// dummy element
        if(0 === count($this->getElement()->getValue()))
            $values[] = null;
        else {
            $values = array_merge($values, $this->getElement()->getValue());
        }
        return $this->wrapValues($values);
    }
    protected function appendMoreLink() {
        $attr = new VA_AttributeDictionary();
        $attr->Set('class', 'ajaxLink');
        $attr->Set('class', 'moreLink');
        $attr->Set('href', '#');
        return sprintf('<li class="more"><a %s>%s</a></li>'
                , $attr
                , 'загрузить еще'
        );
    }
    protected function dummyElement() {
        return $this->wrapOne(null);
    }

    /**
     *
     * @param array $values
     * @return string
     */
    protected function wrapValues($values) {
        $return = '';
        foreach ($values as $value)
            $return .= $this->wrapOne($value);
        $return .= $this->appendMoreLink();
        return sprintf('<ul class="files">%s</ul>', $return);
    }
}
